import EventCenter from "../../TFrame/script/helper/EventCenter";
import ActionHelper from "../../TFrame/script/helper/ActionHelper";
import DailyRewardManager from "../DailyRewardManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ShowDailyDialog extends cc.Component {

    protected onLoad(): void {
        let day = DailyRewardManager.getInstance().currentCanGetDay();
        if(day == -1) {
            this.node.active = false;
        } else {
            cc.tween(this.node).repeatForever( ActionHelper.getBreathAction(1.5)).start()
            EventCenter.once("DailyRewardGet", ()=>{
                this.node.active = false;
            }, this)
        }
    }
    show(e) {
        let node = e.target as cc.Node;
        let btn = node.getComponent(cc.Button);
        btn.enabled = false
        cc.assetManager.getBundle("GameAb").load('prefab/daily', cc.Prefab, (err: Error, pf: cc.Prefab) => {
            btn.enabled = true;
            if(err)
                return console.error(err.message);
            let dialog = cc.instantiate(pf);
            dialog.parent = cc.Canvas.instance.node
        })
    }
}
